<!-- iCheck -->
<script src="/static/plugins/icheck/icheck.min.js"></script>
<!-- 验证插件 -->
<script src="/static/plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="/static/plugins/jquery-validation/localization/messages_zh.min.js"></script>
<!-- 针对当前主题进行简单封装，精简代码 -->
<script src="/static/sdtheme/scripts/sdvalidate.js"></script>
<script>
    $(function () {
        pageInit();        
    })
    function pageInit() {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
        //验证
        validateInfo();
    }
    //表单验证及AJAX提交
    function validateInfo() {
        var $thisForm = $('#thisForm');
        $thisForm.sdvalidate({
            rules: {
                UserName: {
                    maxlength: 24,
                    required: true
                },
                UserPwd: {
                    maxlength: 24,
                    required: true
                },
            },
            messages: {
                UserName: {
                    maxlength: "长度不大于24位",
                    required: "请输入用户名"
                },
                UserPwd: {
                    maxlength: "长度不大于24位",
                    required: "请输入密码"
                },

            },
            submitHandler: function (form) {
                var url = '{{ urlfor "HomeController.DoLogin"}}'
                var data = $thisForm.serialize();
                $.sdpost(url, data, function (re) {
                    if (re.code === 0) {                       
                        window.location.href='{{ urlfor "HomeController.Index"}}'                                         
                    } else {
                        layer.alert(re.msg, { icon: 2, title: '失败' })
                    }
                });
                return false;
            }
        });
    }
    function resetData(){
      layer.confirm('初始化将会重置数据库到作者发布时状态，是否继续', 
        {icon: 3, title:'请确认'}, 
        function(index){  
          var url = '{{ urlfor "HomeController.DataReset"}}'          
          $.sdpost(url, {}, function (re) {
            if (re.code === 0) {                       
                layer.alert(re.msg, { icon: 1, title: '成功' })                   
            } else {
                layer.alert(re.msg, { icon: 2, title: '失败' })
              }
          });
          layer.close(index);
        })
    }
    function FormSubmit() {
        $("#thisForm").submit();
    }
</script>